
package com.seekting.study;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class TestSocketServer {

    public static void main(String[] args) {
        int port = 8899;
        try {
            ServerSocket serverSocket = new ServerSocket(port);
            Socket socket = serverSocket.accept();
            InputStreamReader inputStreamReader = new InputStreamReader(socket.getInputStream());
            StringBuilder sb = new StringBuilder();
            char[] datas = new char[64];
            int length = 0;
            while ((length = inputStreamReader.read(datas)) != -1) {
                sb.append(new String(datas, 0, length));
            }
            System.out.println("from client: " + sb);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println("over");

    }
}
